using Magiq.Update;

namespace Magiq.Sql {
  public class MagiqToSqlUpdateProvider : IUpdateProvider {
    private readonly IDependentTablesUpdateStrategy dependentTablesUpdateStrategy;

    public MagiqToSqlUpdateProvider(IDependentTablesUpdateStrategy dependentTablesUpdateStrategy) {
      this.dependentTablesUpdateStrategy = dependentTablesUpdateStrategy;
    }

    #region IUpdateProvider Members

    public int Execute<T>(IQueryableUpdate<T> update) where T : class {
      var dataContext = update.Where.DataContext();

      var massUpdate = new MassUpdate<T>(update, dataContext, dependentTablesUpdateStrategy);
      return massUpdate.Execute();
    }

    #endregion
  }
}